package com.vrv.netmgr.service;

import com.vrv.common.GlobalConstants;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;

/**
 * 后台主service
 * @author zxb
 *
 */
public class MainService extends Service{
	private static final String TAG = MainService.class.getSimpleName();
	private static final boolean DEBUG = true && GlobalConstants.DEBUG;
	
	@Override
	public IBinder onBind(Intent intent) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void onCreate() {
		super.onCreate();
		if (DEBUG) Log.d(TAG, "onCreate()");
		
		startHeartDetect();
		
		startLocalCache();
	}
	
	/**
	 * 心跳探测服务器是否在线
	 */
	public void startHeartDetect(){
		if (DEBUG) Log.d(TAG, "startHeartDetect()");
		
	    AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
	    PendingIntent pi = PendingIntent.getService(this, 0, new Intent(this, HeartService.class), Intent.FLAG_ACTIVITY_NEW_TASK);
	    am.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), /*15 * 60 */ 1000 * 5, pi);
	}
	
	/**
	 * 本地缓存入口
	 */
	public void startLocalCache(){
		if (DEBUG) Log.d(TAG, "startLocalCache()");
		
	    AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
	    PendingIntent pi = PendingIntent.getService(this, 0, new Intent(this, OfflineDownService.class), Intent.FLAG_ACTIVITY_NEW_TASK);
	    am.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), /*15 * 60 */ 1000 * 10, pi);
	}

}
